/*index.html文件所在的目录*/
jsBridge.log = console.log
localStorage.setItem(dict.CACHE_USER, JSON.stringify({
  userId: '1111-2222-3333-4444-5555',
  username: '测试用户',
  isGuest: false,//是否是游客
  roles: ['GUEST'], // GUEST 游客；REGISTER 注册用户; ENTERPRISE 机构用户；SUBSCRIBER 付费用户
}))

const web = {
  http(data, resolve, reject) {
    let {url, data: params, options} = data

    const config = {
      success(result, status, request) {
        const auth = request.getResponseHeader('Authorization')
        if (auth) {
          localStorage.setItem('IMS_Authorization', auth)
        }
        if (status === 'success') {
          if (Utils.isEmpty(result.code)) {
            resolve(result)
          } else if (result.code === -1) {
            //仅当后台系统抛出异常，说明接口调用失败
            reject(result)
          } else if (result.code === -9) {
            //清除用户信息
          } else {
            resolve(result)
          }
        }
      },
      contentType: 'application/json',
      data: options.contentType === ContentType.FORM ? params || {} : JSON.stringify(params || {}),
      dataType: 'json',
      timeout: 30000,
      type: options.method || 'POST',
      error: reject,
      url: url
    }

    if (options.contentType) {
      config.contentType = options.contentType === ContentType.FORM ? 'application/x-www-form-urlencoded;charset=UTF-8' : 'application/json'
    }

    const token = localStorage.getItem('IMS_Authorization')
    
    if (token) {
      config.headers = {'Authorization': token}
      config.headers = {'token': '5cd541d57f259593244c70b8ad035090'}
      // config.headers = {'token': '3de7dae4593ccf0d86b0a6230fb23e99'}
      // console.log(config, '111')
    }

    $.ajax(config)
  },
  openWindow(data) {
    if (!data) {
      return
    }
    bridgeUtils.beforeOpenWindow(data)
    const {url} = data
    if (url.indexOf('http://') === 0 || url.indexOf('https://') === 0) {
      location.href = url
    } else {
      location.href = dict.ROOT_PATH() + url
    }
  },
  closeWindows() {
    window.history.back()
  },
  setTitle(data) {
  },
  login(data, resolve, reject) {
  },
  logout(data, resolve) {
  },
  setData(data, resolve) {
    if (!data) {
      return
    }
    const {key, value} = data
    localStorage.setItem(key, value)
    resolve(JSON.stringify(value))
  },
  getData(data, resolve) {
    if (!data) {
      return
    }
    resolve(localStorage.getItem(data.key))
  },
  delData(data) {
    if (!data) {
      return
    }
    localStorage.removeItem(data.key)
  },
  clearData() {
    localStorage.clear()
  },
  goBack() {
    window.history.back()
  },
  allowZoom() {
  },
  toast(data) {
    if (!data) {
      return
    }
    alert(data.msg)
  },
  setStatusBarFontColor() {
  },
  getSystemConfig(data = {}, resolve) {
    //Utils.http(dict.API_HOST + "customer/information/public/getLastVersion", {
    //    version: dict.VERSION
    //}).then(function (data) {
    resolve(dict.SYSTEM_CONFIG || {
      server: {
        // 'jt2': 'http://10.128.32.68:82',
        //'jt2': 'http://127.0.0.1',
        'jt2': 'dev11.jd.com',

        'gateWay': 'http://172.25.64.185:8081',
      },
      statusBarHeight: 0.4,
      driveId: '1111-2222-3333-4444',
      version: '1.0.0',
      lastVersion: data.lastVersion,
      state: data.state
    })
    //});
  },
  thirdLogin(data, resolve) {
  },
  share(data, resolve) {
  },
  exchangeTabPage(data) {
    if (data.page === 0) {
      jsBridge.callBridge('openWindow', {url: 'html/index_lw.html'})
    } else if (data.page === 2) {
      jsBridge.callBridge('openWindow', {url: 'html/dataGo/index.html'})
    } else if (data.page === 3) {
      jsBridge.callBridge('openWindow', {url: 'html/index_fw.html'})
    } else if (data.page === 4) {
      jsBridge.callBridge('openWindow', {url: 'html/user/index.html'})
    }
  },
  nativeCalendar(data, resolve) {
    resolve(data)
  },
  openBrsDetail(data) {
  },
  openStock() {
  },
  getCurrentVoice() {
  }
}
